from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class PageNum(PageNumberPagination):
    page_size = 6  # 后端指定每页显示数量
    page_query_param = 'page'
    max_page_size = 5

    # 重写分页返回方法，按照指定的字段进行分页数据返回
    def get_paginated_response(self, data):
        return Response({
            'count': self.page.paginator.count,  # 总数量
            'results': data,  # 数据
            'next': self.get_next_link(),
            'previous': self.get_previous_link()
        })
